Add test for precision conversion with decl_hdf5#672
Add test for precision conversion with decl_hdf5#672Yushan-Wang wants to merge 72 commits intopdidev:mainfrom
decl_hdf5#672Conversation
Removed check for HDF5 version greater than 2.0.0 and related variable assignment.
…ushan-Wang/pdi into precision-conversion-with-hdf5
059513f to
12dff81
Compare
|
Do you feel it would be a good candidate to demonstrate the use of #669 ? |
…into patch-hdf5-2.0.0
Co-authored-by: Julien Bigot <jbigot@users.noreply.github.com>
Co-authored-by: Julien Bigot <jbigot@users.noreply.github.com>
jmorice91
left a comment
There was a problem hiding this comment.
look goods for me.
If your input double data is 1.5d0=1.50...0, how to know that the convention between HDF5 and gtest for transformation of double to int is the same?
Have you tested that?
As we use random number, it is a rare event that is arrived.
HDF5 truncates floating-point numbers to integers upon precision conversion. So 1.5 would be output as 1. Same for static_cast |
c257c27 to
ce93f25
Compare
| ASSERT_GE(status, 0); | ||
|
|
||
| #if defined(__clang__) && (__clang_major__ == 15) | ||
| // Skipping the numerical comparaison because Clang 15 has known issues with ranges. |
There was a problem hiding this comment.
Perhaps do something like that in case we have issue with ranges,
std::array<std::array<int, N>, N> expected_int_array;
for( int ii=0; ii<test_array.size(); ++ii) {
std::transform(test_array[ii].cbegin(), test_array[ii].cend(), expected_int_array[ii].begin(),
[](auto aa){ return static_cast<int>(aa); });
}
// comparison
EXPECT_EQ(expected_int_array, read_int_array);| hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); | ||
| hid_t type_id = H5Dget_type(dataset_id); | ||
|
|
||
| EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); |
There was a problem hiding this comment.
An error of value "-1" would pass this check ?
| EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); | |
| EXPECT_GT(H5Tequal(type_id, H5T_IEEE_F64LE), 0); |
| dataset_id = H5Dopen2(file_id, "/float_ds", H5P_DEFAULT); | ||
| type_id = H5Dget_type(dataset_id); | ||
|
|
||
| EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); |
There was a problem hiding this comment.
Similar to EXPECT_TRUE issue of H5T_IEEE_F64LE
| dataset_id = H5Dopen2(file_id, "/int_ds", H5P_DEFAULT); | ||
| type_id = H5Dget_type(dataset_id); | ||
|
|
||
| EXPECT_TRUE(H5Tequal(type_id, H5T_STD_I32LE)); |
There was a problem hiding this comment.
Similar to EXPECT_TRUE issue of H5T_IEEE_F64LE
| hid_t file_id = H5Fopen("d2d_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); | ||
| hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); | ||
| hid_t type_id = H5Dget_type(dataset_id); |
There was a problem hiding this comment.
May also check for read failure ?
| hid_t file_id = H5Fopen("d2d_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); | |
| hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); | |
| hid_t type_id = H5Dget_type(dataset_id); | |
| hid_t file_id = H5Fopen("d2d_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); | |
| hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); | |
| hid_t type_id = H5Dget_type(dataset_id); | |
| ASSERT_GE(file_id, 0); | |
| ASSERT_GE(dataset_id, 0); | |
| ASSERT_GE(type_id, 0); |
| EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); | ||
| std::array<std::array<double, N>, N> read_double_array; | ||
|
|
||
| herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_double_array.data()); |
There was a problem hiding this comment.
Pointer is not only a double, as it includes the static constexpr size_t N
| herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_double_array.data()); | |
| herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &read_double_array[0][0]); |
| EXPECT_FALSE(std::filesystem::exists("d2f_test.h5")); | ||
| EXPECT_FALSE(std::filesystem::exists("d2i_test.h5")); | ||
|
|
||
| static constexpr size_t const N = 100; |
There was a problem hiding this comment.
constexpr of a const
| static constexpr size_t const N = 100; | |
| static constexpr size_t N = 100; |
| EXPECT_FALSE(std::filesystem::exists("d2d_test.h5")); | ||
| EXPECT_FALSE(std::filesystem::exists("d2f_test.h5")); | ||
| EXPECT_FALSE(std::filesystem::exists("d2i_test.h5")); |
There was a problem hiding this comment.
Should we use std::filesystem::remove() before, to be sure ?
| endforeach(test_name) | ||
|
|
||
| add_executable(decl_hdf5_conversion_test decl_hdf5_precision_conversion_test.cxx) | ||
| target_link_libraries(decl_hdf5_conversion_test ${HDF5_DEPS} PDI::PDI_C GTest::gmock GTest::gmock_main GTest::gtest GTest::gtest_main) |
There was a problem hiding this comment.
Do GTest::gtest_main and GTest::gmock_main overlink ? Two other files of the repo also use this
| auto const test_array = make_a<std::array<std::array<double, N>, N>>(); | ||
| PDI_expose("array", test_array.data(), PDI_OUT); | ||
|
|
||
| EXPECT_TRUE(std::filesystem::exists("d2d_test.h5")); |
There was a problem hiding this comment.
Perhaps, we should use assert her because if we don't have the file the comparison test
for double doesn't make any sense
| EXPECT_TRUE(std::filesystem::exists("d2d_test.h5")); | |
| ASSERT_TRUE(std::filesystem::exists("d2d_test.h5")); |
List of things to check before making a PR
Before merging your code, please check the following:
.clang-format;Fix #issuekeyword to autoclose the issue when merged.